home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr49
/
107_01.zip
/
FIO.1
< prev
next >
Wrap
Text File
|
1993-06-06
|
5KB
|
145 lines
/*********************************************
* This source code was contributed by: *
* *
* Eric Martz *
* Department of Microbiology *
* University of Massachusetts *
* Amherst, MA 01003 *
* *
* Phones: *
* *
* Day: 413-545-2325 *
* Evenings: 413-256-0751 *
* *
*********************************************/
/* This file is part of a set of three inclusions (fio.1, fio.2, fio.3)
designed to permit the writing of source codes as close as possible to K&R C,
where only "fp = fopen(filename,mode)" is needed to allocate an i/o buffer,
etc. By using this plan, a source code can be portable between a minicomputer
Unix-C system and BSDC. To move the code from the latter to the former, one
need only delete the three "includes". Here is an example of the use of these
inclusions in a "word count" program:
---------------------------------------------------------
#include "bdscio.h"
#define NIOBUFS 1
#include "fio.1"
main(argc,argv)
int argc;
char **argv;
{
#include "fio.2"
if (argc == 1) {
printf("Use: wc filename\n");
exit(0);
}
allcnt(argv[1]);
}
allcnt(name)
char *name;
{
unsigned linecnt, charcnt, wordcnt, crcnt, longline;
int white, linelen, longest;
int c;
FILE *fp;
fp = fopen(name,"r");
/* [OMITTED HERE IS THE BODY OF THE FUNCTION ] */
/* IF NEEDED, E. G. FOR WRITING A FILE: */
fclose(fp);
}
#include "fio.3"
---------------------------------------------------------*/
/* Another example of use may be found in the file backup utility fi.c */
/* THIS SEGMENT (fio.1) DECLARES THE I/O BUFFERS NEEDED (_iob), AND A SET OF
FLAGS TO KEEP TRACK OF WHICH ONES ARE IN USE AN ANY GIVEN TIME (bufuse). TAKE
THE EXAMPLE OF A PROGRAM WHICH NEEDS TO HAVE TWO FILES OPEN AT ONCE. MANY MORE
THAN TWO FILES MAY BE OPENED AND CLOSED, BUT WE ARE SUPPOSING THAT NOT MORE
THAN TWO NEED TO BE OPEN SIMULTANEOUSLY. THE "#include fio.1" MUST BE PRECEDED
BY "#define NIOBUFS 2". THIS MEANS _iob[0] THRU _iob[1]. HOWEVER, bufuse[0] IS
USED TO STORE NIOBUFS, THUS THE FIRST BUFFER _iob[0] CORRESPONDS TO THE
BUFFER-USE-FLAG bufuse[1]. */
char _iob[NIOBUFS][BUFSIZ];
int bufuse[NIOBUFS+1];
/* End of fio.1 */
ongline;
int white, linelen, longest;
int c;
FILE *fp;
fp = fopen(name,"r");
/* [OMITTED HERExistent or empty.